package com.xiangge.oop;
/*
      面向对象的三大特性： 封装  继承  多态
      封装：
         方法封装： 将 一段特定功能的代码封装到方法中，只需要调用方法即可，提高了代码的复用性
         面向对象中的封装：将属性和行为封装到对象中，然后提供一个对外访问的窗口： 对象 , 那么我们可以使用改对象调用对象中的任意一个属性和行为
 */
public class OopDemo5 {
    public static void main(String[] args) {
      print(10, 20);
      print(3,4);

        Bird bird = new Bird();
        bird.eat();
        bird.eat();
        bird.setAge(20);
        bird.setName("小鸟");

        Bird bird2 = new Bird("小鸽", 10, 0.5);
        bird2.eat();
        bird2.eat();
        bird2.eat();
        bird2.eat();
        bird2.eat();

        bird2.setName("小鸽2");
        bird2.setName("小鸽2");
        bird2.setName("小鸽2");
        bird2.setName("小鸽2");



    }

    public static void print(int a, int b){
        System.out.println(a + b);
    }
}

/*
    鸟类
 */
class Bird{
    // 私有属性
    private String name;
    private int age;
    private double weight;

    // 构造方法
    public Bird() {
    }

    public Bird(String name, int age, double weight) {
        this.name = name;
        this.age = age;
        this.weight = weight;
    }

    // setter and getter
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    // 行为
    public void eat(){
        System.out.println("鸟吃小虫");
    }
}
